﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL.Gateway;
namespace DAL.DataFramework
{
    public class ConnectorsDAL<T>:IDisposable
    {
        private string SelectDataTransactionGuid = "7EA494B2-836F-41FA-88AB-DA166A98036D";
        private string CreateDataTransactionGuid = "E0412D21-78E8-4045-9D57-4B6E41FD9A3A";
        private string UpdateDataTransactionGuid = "CB8A7A17-38A3-4B2B-90FE-34EF754061A4";
        private string DeleteDataTransactionGuid = "F9928929-B6C1-4407-AB92-D7F36A650DEA";
        private string ExistsConnectorNameGuid = "D73CA3EA-6B50-4096-9C5D-2F60D91B01AF"; // Falsa
        private string ExistsConnectorIdGuid = "D73CA3EA-6B50-4096-9C5D-2F60D91B01AF"; // Falsa

        internal T Create(string sConnectorName)
        {
            try
            {
                T Resultado = new GenericList<T>().GetAGenelicListOf(
                    DataAccessGateway.TraerDataTable(CreateDataTransactionGuid, sConnectorName)).Single<T>();
                return Resultado;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectorsDA - Create - ", ex);
            }
        }
        internal T Update(int iConnectorId, string sConnectorName, bool bActive)
        {
            try
            {
                T Resultado = new GenericList<T>().GetAGenelicListOf(
                    DataAccessGateway.TraerDataTable(UpdateDataTransactionGuid,iConnectorId,sConnectorName,bActive)).Single<T>();
                return Resultado;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectorsDA - Update - ", ex);
            }
        }
        internal bool Delete(int iConnectorId)
        {
            try
            {
                return
                    DataAccessGateway.Ejecutar(DeleteDataTransactionGuid,iConnectorId) > 0 ? true : false;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectorsDA - Delete - ", ex);
            }
        }
        internal bool ExistsConnectorName(string ConnectorName)
        {
            try
            {
                return
                    DataAccessGateway.Ejecutar(ExistsConnectorNameGuid,ConnectorName) > 0 ? true : false;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectorsDA - ExistsConnectorName - ", ex);
            }
        }
        internal bool ExistsConnectorId(int Id)
        {
            try
            {
                return
                    DataAccessGateway.Ejecutar(ExistsConnectorIdGuid,Id) > 0 ? true : false;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectorsDA - ExistsConnectorId - ", ex);
            }
        }
        internal List<T> Select(int iConnectorId, string sConnectorName, bool bActive)
        {
            try
            {
                return new GenericList<T>().GetAGenelicListOf(
                    DataAccessGateway.TraerDataTable(
                    SelectDataTransactionGuid,
                    iConnectorId,
                    sConnectorName,
                    bActive));
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectorsDA - Select - ", ex);
            }
        }

        public void Dispose()
        {
        }
    }
}
